<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>权限分配</title>
    <%@include file="/views/header.jsp" %>
</head>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space10">
    <div class="layui-col-md9 layui-col-xs11">
           <div class="ibox-title" style="margin-left:50px;">
               <h5>角色:admin</h5>
           </div>
        <div class="layui-form-item magt3" style="margin-left:50px;">
            <div class="ibox-content">
                <ul id="zTree" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="layui-form-item magt3" style="margin-left:50px;">
        <a class="layui-btn layui-btn-sm btn_save" ><i class="layui-icon">&#xe609;</i>提交</a>
        <a class="layui-btn layui-btn-sm btn_close" ><i class="layui-icon">&#xe609;</i>取消</a>
    </div>

</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script type="text/javascript">
    $(function () {
        //获取窗口索引
        var index = parent.layer.getFrameIndex(window.name);
        //取消按钮
        $(".btn_close").bind("click", function () {
            parent.layer.close(index);
        });
        //提交按钮
        $(".btn_save").bind("click", function () {
            var ids = Feng.zTreeCheckedNodes("zTree");
            var params ={
                "ids":ids,//权限id
                "roleId":"${roleId}"
            };
           $.post(Feng.ctxPath+"/role/setAuthority",params,function(data){
                var msg = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
                if(data.success){
                    setTimeout(function(){
                        top.layer.close(msg);//关闭提示
                        top.layer.msg(data.message);//提示成功信息
                        parent.layer.close(index);//关闭弹框
                        window.parent.location.reload();//刷新父页面
                    },500);
                }else{
                    top.layer.close(msg);
                    top.layer.msg(data.message);
                }
            },"json");
        });

        initZtree();
    });

    function initZtree() {
        var setting = {
            check: {
                enable: true,
                chkboxType: { "Y": "ps", "N": "ps" }
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };

        var ztree = new $ZTree("zTree", "/sysMenu/menuTreeListByRoleId/"+ "${roleId}");
        ztree.setSettings(setting);
        ztree.init();
    }
</script>
</body>
</html>